#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> resultsArray(vector<int>& nums, int k) {
        if (k == 1) return nums;
        int flag = 0, cur = 1;
        int n = nums.size();
        vector<int> res;
        while (cur < n)
        {
            if (nums[cur] != nums[cur - 1] + 1) flag = k;
            if (flag > 0) flag--;
            if (cur >= k - 1 && flag == 0) res.push_back(nums[cur]);
            else if (cur >= k - 1 && flag > 0) res.push_back(-1);
            ++cur;
        }
        return res;
    }
};